﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;
using BLL;

namespace CSMF
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindNews();
                BindVideo();
                BindLatest();
                BindHighest();
                BindMost();
                BindMayor();
            }
        }

        protected string GetStyle1(object vid)
        {
            string style = "";
            if (vid == null)
            {
                style = "item selected";
            }
            else
            {
                if (Convert.ToString(vid).Equals("1"))
                {
                    style = "item selected";
                }
                else
                {
                    style = "item";
                }
            }
            return style;
        }

        protected string GetStyle2(object vid)
        {
            string style = "";
            if (vid == null)
            {
                style = "item";
            }
            else
            {
                if (Convert.ToString(vid).Equals("2"))
                {
                    style = "item selected";
                }
                else
                {
                    style = "item";
                }
            }
            return style;
        }

        protected string GetStyle3(object vid)
        {
            string style = "";
            if (vid == null)
            {
                style = "item";
            }
            else
            {
                if (Convert.ToString(vid).Equals("3"))
                {
                    style = "item selected";
                }
                else
                {
                    style = "item";
                }
            }
            return style;
        }

        protected string GetType(string typeId)
        {
            string type = "";
            if (typeId != "")
            {
                string[] cloths = typeId.Split(',');
                int id = Convert.ToInt32(cloths[0]);
                VideoType vt = VideoTypeManager.GetVideoTypeByID(id);
                type = vt.Title;
            }
            return type;
        }

        protected string GetPoint(int id)
        {
            string point = "";
            Models.VideoInfo info = VideoInfoManager.GetVideoInfoByID(id);
            if (info.Point == 0)
            {
                point = Convert.ToSingle((VideoPointManager.GetVideoPointsSumByVideoID(id) / VideoPointManager.GetVideoPointsCountByVideoID(id))).ToString("0.0");
                if (point.Equals("非数字"))
                {
                    point = "0";
                }
            }
            else
            {
                point = info.Point.ToString("0.0");
            }
            return point;
        }


        protected void BindMayor()
        {
            IList<Mayor> pic = MayorManager.GetMayorsByTop10();
            rptMayor.DataSource = pic;
            rptMayor.DataBind();
        }


        protected void BindNews()
        {
            IList<NewsInfo> pic = NewsInfoManager.GetNewsInfosByTypeIDIndex("2,3");
            rptNews.DataSource = pic;
            rptNews.DataBind();
        }

        protected void BindVideo()
        {
            IList<Models.VideoInfo> pic = VideoInfoManager.GetVideoInfosTop10();
            rptVideo.DataSource = pic;
            rptVideo.DataBind();
        }

        protected void BindLatest()
        {
            IList<Models.VideoInfo> pic = VideoInfoManager.GetVideoInfosTop10Latest();
            rptLatest.DataSource = pic;
            rptLatest.DataBind();
        }

        protected void BindHighest()
        {
            //IList<VideoInfo> pic = VideoInfoManager.GetVideoInfosTop10ByPoint();
            //rptHighest.DataSource = pic;
            //rptHighest.DataBind();
            IList<View_Point> pic = View_PointManager.GetAllView_Points();
            rptHighest.DataSource = pic;
            rptHighest.DataBind();
        }

        protected void BindMost()
        {
            IList<Models.VideoInfo> pic = VideoInfoManager.GetVideoInfosTop10ByCount();
            rptMost.DataSource = pic;
            rptMost.DataBind();
        }
    }
}
